feat: add strict event type checking #10235
Open
+860
−1,198
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
eventDetails
fieldThis change is introducing a new field in the components
This field doesn't have runtime semantics, it is only used to provide type information about the events that the component is firing and the corresponding types of the detail parameter.
This enables two new usages
strict
@event
decoratorThere is a new event decorator that does strict checks against this field. The old event decorator is deprecated and will be removed. To switch, simple change the import
It is no longer necessary to priovide the event type in the decorator, as TypeScript is able to infer it from the event name and the
eventDetails
field.strict
fireDecoratorEvent
The method
fireDecoratorEvent
is now also checking against theeventDetails
field ensuring that the event name that is fired is described and that the detail parameter is of the same type as the one ineventDetails
. The event type is also inferred from the event name and no longer necessary to pass from outside.extending the
eventDetails
with more eventsIf your component extends another component and you try to add new events, you will get a TypeScript error that the new events cannot be assigned to the same field in the base class
In order to correctly extend the base class events, you need to add them as a type as well like this
TimePickerInternals["eventDetails"]